
#include "ruler.h"

typedef struct ruler_t
{
	hashTable rulesHash;
}ruler_t;



void addRule(ruler _ruler, int port, char* protocol) 
{
	insertRule(_ruler->rulesHash, port, protocol);
	return;
    
}


char* protocolByPort(ruler _ruler, int port) 
{
    return findProtocol(_ruler->rulesHash, port);
}


ruler createRuler()
{
	hashTable hT = createHashTable(100);
	ruler res;

	if(!hT)
	{
		/*fprintf (stderr, "out of memory (hashTable)\n");
        exit(1);*/
		return NULL;
	}

	if (( res = (ruler)malloc(sizeof(ruler_t))) == 0) {
        /*fprintf (stderr, "out of memory (hashTable)\n");
        exit(1);*/
		destroyHash(hT);
		return NULL;
    }

	res->rulesHash = hT;

	return res;
}


	
void destroyRuler(ruler _ruler)

{
	destroyHash(_ruler->rulesHash);

	free(_ruler);
}


